const Service = require('./index')
const feedbackModel = require('@/models/feedback.model')

class FeedbackService extends Service {
  /**
   * 反馈分页查询
   * @param {*} pageNo
   * @param {*} pageSize
   */
  async findPage (pageNo = 1, pageSize = 20) {
    try {
      const { list, total } = await feedbackModel.findPage({
        pageNo,
        pageSize
      })
      return this.skipPage(list, total, pageNo, pageSize)
    } catch (error) {
      throw new Error(error)
    }
  }

  async delete (id) {
    try {
      const exist = await feedbackModel.exist(id)
      if (!exist) {
        return {
          errorMessage: '反馈不存在'
        }
      }
      await feedbackModel.delete(id)
    } catch (error) {
      throw new Error(error)
    }
  }
}

module.exports = new FeedbackService()
